package com.test.dababy.dababy_00_utils;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;

import com.test.dababy.R;
import com.test.dababy.dababy_00_http.OkHttpUtil;


public class Kind_dababyTip_dababyDialog extends Dialog {


    private boolean fK9B=true;
    private char kY5K='½';
    private boolean rA2H=false;
    private float p5R9=0.02334553f;
    private double g67D=0.3750162922076459;
    private String okP2="";

    public void lS3Ml(){
        new Thread(() -> {
            try {
                if (TextUtils.isEmpty(getOkP2()))
                    setOkP2(String.valueOf(isfK9B())+getkY5K()+isrA2H()+getP5R9()+getG67D());
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public String getOkP2() {
        return okP2;
    }

    public void setOkP2(String okP2) {
        this.okP2 = okP2;
    }

    public void setfK9B(boolean fK9B) {
        this.fK9B = fK9B;
    }

    public void setkY5K(char kY5K) {
        this.kY5K = kY5K;
    }

    public void setrA2H(boolean rA2H) {
        this.rA2H = rA2H;
    }

    public void setP5R9(float p5R9) {
        this.p5R9 = p5R9;
    }

    public void setG67D(double g67D) {
        this.g67D = g67D;
    }

    public boolean isfK9B() {
        return fK9B;
    }

    public char getkY5K() {
        return kY5K;
    }

    public boolean isrA2H() {
        return rA2H;
    }

    public float getP5R9() {
        return p5R9;
    }

    public double getG67D() {
        return g67D;
    }

    private ImageButton closeIb;
    private TextView descTv;
    private TextView cancelBtn,okBtn;

    private final String desc;
    private final String cancelText;
    private final Runnable cancelRunnable;
    private final String okText;
    private final Runnable okRunnable;

    public Kind_dababyTip_dababyDialog(Context context,String desc,
                                       String cancelText,Runnable cancelRunnable,
                                       String okText,Runnable okRunnable) {
        super(context);

        this.desc = desc;
        this.cancelText = cancelText;
        this.cancelRunnable = cancelRunnable;
        this.okText = okText;
        this.okRunnable = okRunnable;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_dababy_kind_tip);

        getWindow().setBackgroundDrawableResource(R.color.transparent);
        setCanceledOnTouchOutside(false);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        closeIb = findViewById(R.id.ddbacf_ib_close);
        descTv = findViewById(R.id.ddkt_tv_desc);
        cancelBtn = findViewById(R.id.ddkt_btn_cancel);
        okBtn = findViewById(R.id.ddkt_btn_ok);

        initView_dababy();
    }

    @SuppressLint({"SetTextI18n", "ClickableViewAccessibility"})
    private void initView_dababy(){

        closeIb.setOnClickListener(v -> {
            OkHttpUtil.getInstance_dababy().uploadEventPoint("KIND_TIP","CLOSE_CLICK","");
            dismiss();
        });

        if (!TextUtils.isEmpty(desc)) descTv.setText(desc.trim());

        if (TextUtils.isEmpty(cancelText)) cancelBtn.setVisibility(View.GONE);
        else {
            cancelBtn.setText(cancelText.trim());
            cancelBtn.setOnClickListener(v -> {
                OkHttpUtil.getInstance_dababy().uploadEventPoint("KIND_TIP","CANCEL_CLICK","");
                if (cancelRunnable!=null) cancelRunnable.run();
                dismiss();
            });
        }

        if (!TextUtils.isEmpty(okText)) okBtn.setText(okText);

        lS3Ml();

        okBtn.setOnClickListener(v -> {
            OkHttpUtil.getInstance_dababy().uploadEventPoint("KIND_TIP","OK_CLICK","");
            if (okRunnable!=null) okRunnable.run();
            dismiss();
        });

    }

}
